import collections
class Solution(object):
    def lemonadeChange(self, bills):
        """
        :type bills: List[int]
        :rtype: bool
        """
        c = collections.defaultdict(int)
        for b in bills:
            if b == 5:
                c[5] += 1
            if b == 10:
                if c[5]:
                    c[5] -= 1
                    c[10] += 1
                else:
                    return False
            if b == 20:
                if c[10]:
                    if c[5]:
                        c[5] -= 1
                        c[10] -= 1
                    else:
                        return False
                else:
                    if c[5] >= 3:
                        c[5] -= 3
                    else:
                        return False
        return True

data = Solution()
bills = [5,5,5,10,20]
print(data.lemonadeChange(bills))